/*
 * u1e1.cc
 *
 *  Created on: Sep 17, 2012
 *      Author: shaohong
 */


#include <iostream>
#include <vector>

using namespace std;


void printNames(vector<string>& names) {

	if (names.empty()) {
		cout << "Error" << endl;
		cout << "No elements in the vector." << endl;
		return;
	}

	for(size_t i=0; i<names.size(); i++) {
		cout << names[i] << endl;
	}
}

void removeName(vector<string>& names) {
	if (names.empty()) {
		cout << "Error" << endl;
		cout << "No removable elements." << endl;
		return;
	}

	cout << "Removing the last element:" << endl;
	cout << names[names.size()-1] << endl;
	names.pop_back();
}

void addName(vector<string>& names) {
	cout << "Enter a name:" << endl;

	string newName;
	cin >> newName;
	names.push_back(newName);

	cout << "Number of names in the vector:" << endl;
	cout << names.size() << endl;

}


string promptUserCommand() {
	cout << "Enter command:" << endl;

	string userCommand;
	cin >> userCommand;

	return userCommand;
}


void executeCommand(vector<string>& names, string command) {
	if (command.compare("PRINT")==0) {
		printNames(names);
	}

	if (command.compare("REMOVE")==0) {
		removeName(names);
	}

	if (command.compare("ADD")==0) {
		addName(names);
	}


}

int main() {

	vector<string> names;

	cout << "Commands: ADD, PRINT, REMOVE, QUIT" << endl;

	string command = promptUserCommand();
	while (command.compare("QUIT") != 0) {
		executeCommand(names, command);
		command = promptUserCommand();
	}

	return 0;
}
